package com.sjlh.centurylianhua.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sjlh.centurylianhua.entity.UserRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

public interface UserRoleMapper extends BaseMapper<UserRole> {
    //多表关联查询
    @Select("SELECT ur.*,r.roleName rolename,u.userName username FROM role r,user u,user_role ur "+" ${ew.customSqlSegment} " )
    List<UserRole> urlist1(@Param("ew") QueryWrapper<UserRole> wrapper);
    //多表分页关联查询
    @Select("SELECT ur.*,r.roleName rolename,u.userName username FROM role r,user u,user_role ur "+" ${ew.customSqlSegment} " )
    List<UserRole> urlist2(Page<UserRole> page, @Param("ew") QueryWrapper<UserRole> wrapper);
    //遍历删除
    @Delete("<script>"+
            "delete from user_role where\n"+
            "<foreach collection='list' item='item' separator='or'>" +
            "(userId=#{item.userId} and roleId=#{item.roleId})</foreach>"+
            "</script>")
     boolean deletelist(@Param(value = "list") List<UserRole> list);
}
